<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>餐桌列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="shortcut icon" href="__STATIC__/favicon.ico" type="image/x-icon"/>
    <link rel="stylesheet" href="__STATIC__/css/font.css">
    <link rel="stylesheet" href="__STATIC__/css/xadmin.css">
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script type="text/javascript" src="__STATIC__/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="__STATIC__/js/xadmin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
    <style>
        .laytable-cell-1-customer_code{height: auto;}
    </style>
</head>

<body class="layui-anim layui-anim-up">
<div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="">首页</a>
        <a href="">店铺管理</a>
        <a>
          <cite>餐桌列表</cite></a>
      </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
       href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">&#xe666;</i></a>
</div>
<div class="x-body">
    <div class="layui-row" style="text-align: center">
        <form class="layui-form layui-col-md12 x-so">
            <div class="layui-input-inline">
                <select name="shop_id" lay-filter="shop_id" lay-verify="required">
                    <option value="">请选择店铺</option>
                    {volist name="data" id="vo"}
                    <option value="{$vo.id}">{$vo.shop_name}</option>
                    {/volist}
                </select>
            </div>
            <input type="text" name="table_no" lay-verify="required" placeholder="请输入桌号" autocomplete="off"
                   class="layui-input">
            <button class="layui-btn" lay-submit="" lay-filter="sreach"><i class="layui-icon"></i>增加</button>
        </form>
    </div>
    <table id="demo" lay-filter="test"></table>

</div>
<script>
    layui.use(['table', 'form','layer'], function () {
        var table = layui.table
            , layer = layui.layer
            , form = layui.form;
        table.render({
            elem: '#demo'
            , url: '{:url("shop/tableData")}' //数据接口
            , page: true //开启分页
            , cols: [[ //表头
                {field: 'id', width: 50, title: 'ID'}
                , {field: 'shop_id', title: '店铺名称'}
                , {field: 'table_no', title: '桌号'}
                , {field: 'customer_code', title: '餐桌二维码', templet: function (d) {
                        if (!d.customer_code) {
                            return '<button class="layui-btn layui-btn-xs" onclick="customerCode(' + d.id + ')">生成二维码</button>';
                        } else {
                            return '<img  src="' + d.customer_code + '" width="50px" height="50px" alt="...">';
                        }
                    }
                }
                , {field: 'waiter_id', title: '绑定员工'}
                , {
                    field: 'status', title: '状态', templet: function (d) {
                        if (d.status == 1) {
                            return '<span class="layui-btn layui-btn-xs layui-btn-normal">正常</span>';
                        } else {
                            return '<span class="layui-btn layui-btn-xs layui-btn-danger">禁用</span>';
                        }
                    }
                }
                , {
                    fixed: 'right', title: '操作', templet: function (d) {
                        return '<a onclick="member_stop(this,' + d.id + ')" href="javascript:;"  title="修改状态"><i class="layui-icon">&#xe642;</i></a>' +
                            '    <a title="删除" onclick="member_del(this,' + d.id + ')" href="javascript:;"><i class="layui-icon">&#xe640;</i></a>';
                    }
                }
            ]]
        });

        form.on('submit(sreach)', function (data) {
            $.post('{:url("shop/tableAdd")}', data.field, function (res) {
                if (res.code == 1) {
                    layer.msg(res.msg, {icon: 1, time: 2000}, function () {
                        location = location;
                    });
                } else {
                    layer.msg(res.msg, {icon: 2, time: 2000});
                }
            });
            return false;
        });
    });
    function customerCode(id) {
        layer.confirm('确认要生成二维码？', function (index) {
            $.post('{:url("shop/customerCode")}', {table_id: id}, function (res) {
                if (res.code == 1) {
                    layer.close(index);
                    window.location.reload();
                } else {
                    layer.msg(res.msg, {icon: 1, time: 1000});
                }
            });
        });
    }

    function member_stop(obj, id) {
        layer.confirm('确认要修改吗？', function (index) {
            $.post('{:url("shop/tableStatus")}', {table_id: id}, function (res) {
                if (res.code == 1) {
                    location = location;
                } else {
                    layer.msg(res.msg, {icon: 1, time: 1000});
                }
            });
        });
    }

    /*用户-删除*/
    function member_del(obj, id) {
        layer.confirm('确认要删除吗？', function (index) {
            //发异步删除数据
            $.post('{:url("shop/tableDel")}',{id:id},function (res) {
                if (res.code == 1) {
                    layer.msg(res.msg,{icon:1,time:1000},function () {
                        location = location;
                    });
                }else {
                    layer.msg(res.msg,{icon:2,time:1000});
                }
            });
        });
    }
</script>
</body>

</html>